package main

import (
	"fmt"
	"sort"
)

func main() {
	var N int
	var A, B string
	_, _ = fmt.Scan(&N, &A, &B)

	var AS, BS []int
	AS = make([]int, N)
	BS = make([]int, N)

	for i := 0; i < N; i++ {
		AS[i] = int(A[i])
		BS[i] = int(B[i])
	}

	sort.Ints(BS)
	f(AS, BS, N)
}

func f(AS, BS []int, N int) {
	var flag bool

	for i := 0; i < N; i++ {
		if BS[i] == AS[i] {
			continue
		}
		if BS[i] < AS[i] {
			flag = true
			for j := i + 1; j < N; j++ {
				BS[i], BS[j] = BS[j], BS[i]
				if BS[i] >= AS[i] {
					flag = false
					break
				}
			}

			if flag {
				for j := i + 1; j < N; j++ {
					if BS[j] > AS[i] {
						BS[i], BS[j] = BS[j], BS[i]
						sort.Ints(BS[i+1:])
						printAns(BS)
						return
					}
				}

				for j := 1; j <= i; j++ {
					if BS[j] > BS[j-1] {
						BS[j], BS[j-1] = BS[j-1], BS[j]
						sort.Ints(BS[j:])
						printAns(BS)
						return
					}
				}
			}
		}
		if BS[i] > AS[i] { // 找到答案
			sort.Ints(BS[i+1:])
			printAns(BS)
			return
		}
	}

	for i := 1; i < N; i++ {
		if BS[i] > BS[i-1] {
			BS[i], BS[i-1] = BS[i-1], BS[i]
			printAns(BS)
			return
		}
	}
	fmt.Println(-1)
}

func printAns(BS []int) {
	for _, v := range BS {
		fmt.Printf("%c", v)
	}
}
